package engine.individuals;

public class BinaryVectorIndividual extends BinaryVector implements
		Individual<Integer> {

	public BinaryVectorIndividual(boolean[] list) {
		super(list);
	}

	public BinaryVectorIndividual(int size) {
		super(size);
	}

	@Override
	public Integer get(int index) {

		return super.getBit(index) == false ? 0 : 1;
	}

	@Override
	public void set(int index, Integer chromosome) {

		super.setBit(index, chromosome == 0 ? false : true);
	}

	@Override
	public int size() {
		return super.getSize();
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		
		if (this == obj) {
			return true;
		}
		
		if (obj == null || getClass() != obj.getClass()) {
			return false;
		}
		
		BinaryVectorIndividual individual = (BinaryVectorIndividual) obj;
		
		if (size() != individual.size()) {
			return false;
		}
		
		boolean isEqual = true;
		
		for (int i = 0; i < size() && isEqual; i++) {
			if (!get(i).equals(individual.get(i))) {
				isEqual = false;
			}
		}
		
		return isEqual;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		
		int hash = 0;
		
		for(int i = 0; i < 0; ++i)
		{
			hash <<= 1;
			hash += get(i);
		}
		
		return hash;
	}

	@Override
	public void heal() {
		// nothing to do
	}
}
